/*AyflEomXWyqCHfdTxzWda3ExHehXzPX6thlzEnTk9yg=*/
import { afterEvent, initTemplate, buttonClick ,formBeforeEvent} from './events/index';
import { ajax, base, createPage, toast, getMultiLang ,getBusinessInfo} from 'nc-lightapp-front';
import React, { Component } from 'react';
import './index.less';
const tableid = 'list';
class DebTransFormComponent extends Component {
    constructor(props) {
        super(props);
        props.use.form("form");
        this.state={
            pk_org:null,
            m_sClrq:null,//转移日期
            pk_ratetype:null,
            m_sCurrency:null
        }
       // this.pk_org;
    }
    componentWillMount(nextProps) {
        let callback = (json) => {
            this.setState({ json: json }, () => {
                initTemplate.call(this, this.props, this.initShow);
            });
        };
        getMultiLang({ moduleId: 'public', domainName: 'arap', currentLocale: 'simpchn', callback });

    }
    componentDidMount() {
        this.props.onRef(this);
    }
    initShow = () => {
        let { selectcons, selectObj, filterObj } = this.props;
        this.renderData(selectObj);
        this.state.pk_org = filterObj.pk_org.value;
    }

    renderData = (selectObj)=>{
		let keys = Object.keys(selectObj);//对象属性名称
		let busiinfo = getBusinessInfo();
		let rateAndRateDateEdit =selectObj.rateAndRateDateEdit;
		let rateTyepEdit = selectObj.rateTyepEdit;
        for (var key = 0; key < keys.length; key++) {
            var name = keys[key];
            this.props.form.setFormItemsValue("form", { [name]: { value: selectObj[name].value, display: selectObj[name].display } });
        }
		this.props.form.setFormStatus("form", "edit");

        let field = { 'pk_ratetype': rateTyepEdit, 'ratedate': !rateAndRateDateEdit, 'm_dBbhl': !rateAndRateDateEdit, 'm_sClrq': false, 'm_izrWldx': false, 'm_sToObBm': false,'m_sFromObBm':true,'m_sCurrency':true,'m_izcWldx':true}
        this.props.form.setFormItemsDisabled("form", field);
		//设置转移日期默认值
		this.props.form.setFormItemsValue("form",{'m_sClrq':{value:busiinfo.businessDate,display:busiinfo.businessDate}})
		this.state.m_sClrq =selectObj.m_sClrq.value;
		this.state.pk_org  = selectObj.pk_org;
        this.state.m_sCurrency = selectObj.m_sCurrency.value;//币种编码待改
    }

    handleTransfers = () => {
		let { selectObj, filterObj } = this.props;
		let { m_sFromOb } = filterObj;
       // let {m_izrWldx } = selectObj;
		let m_sToObBm = this.props.form.getFormItemsValue('form','m_sToObBm');//m_sToObBm
		let m_sClrq = this.props.form.getFormItemsValue('form','m_sClrq');//m_sClrq
		let ratedate = this.props.form.getFormItemsValue('form','ratedate');
		let m_izcWldx = this.props.form.getFormItemsValue('form','m_izcWldx');//m_izcWldx
		let m_izrWldx = this.props.form.getFormItemsValue('form','m_izrWldx');
		let m_dBbhl = this.props.form.getFormItemsValue('form','m_dBbhl');
		let pk_ratetype = this.props.form.getFormItemsValue('form','pk_ratetype');
		let arrIndex = [];
		let selectedData = this.props.getSelectedData();
		if (selectedData.length > 0) {
			let mValue = '';
			//let m_sFromObVal = filterObj.m_sFromOb.value;
			let key = Number(filterObj.m_sFromOb.value);
			switch (key) {
				case 0:
				case 1:
					mValue = filterObj.m_sKsbm.value;
					break;
				case 2:
					mValue = filterObj.m_sBmbm.value;
					break;
				case 3:
					mValue = filterObj.m_sYwybm.value;
					break;
			}
			if (mValue == m_sToObBm.value) {
				toast({
					color: 'warning',
					content: this.state.json['public-000203'] /* 国际化处理： 转出户与转入户不能相同*/
				});
			} else {
				if (m_sToObBm.value && m_dBbhl.value && m_sClrq.value) {
					for (var i = 0, len = selectedData.length; i < len; i++) {
						if (selectedData[i].data.values.this_sett.value != null) {
							arrIndex.push(selectedData[i].index);
						}
					}
					// 右边的条件
					let selectObjData = {
						m_dBbhl: m_dBbhl.value, //本币汇率
						m_iBz: 0, //并账标志
						m_iCurrDig: 0, // 币种小数位数
						m_izrWldx: m_izrWldx.value, //转入往来对象
						m_izcWldx: m_izcWldx.value, //转出往来对象
						m_sClrq: m_sClrq.value , //处理日期
						m_sCurrency: selectObj.m_sCurrency.value, //币种编码
						m_sDwbm: filterObj.pk_org.value, //m_sDwbm;/* 单位编码 */
						m_sFromObBm: selectObj.m_sFromObBm.value, //转出户
						m_sSfbz: this.props.sfbz, //收付标志
						m_sToObBm: m_sToObBm.value, //转入户
						pzglh: 0,
						m_bIsDocument: true,
						accountDateZone: m_sClrq.value, //并账日期
                        m_sAccountDate: m_sClrq.value,//并账日期
                        pk_ratetype:pk_ratetype.value,
                        ratedate:ratedate.value
					};
					// 左边的条件
					let filterObjData = {
						m_bIsDocument: true, //核销方式
						ar29: false,
						pk_org: filterObj.pk_org.value,
						m_sFromOb: filterObj.m_sFromOb.value,
						m_sKsbm: filterObj.m_sKsbm.value,
						m_sYwybm: filterObj.m_sYwybm.value,
						m_sBmbm: filterObj.m_sBmbm.value,
						m_sCurrency: filterObj.m_sCurrency.value,
						m_sDjlx: filterObj.m_sDjlx.value,
						m_zrbm: filterObj.m_zrbm.value,
						m_sMinDjbh: filterObj.m_sDjbh[0].value,
						m_sMaxDjbh: filterObj.m_sDjbh[1].value,
						m_sDjrqBeg: filterObj.m_sDjrq[0],
						m_sDjrqEnd: filterObj.m_sDjrq[1],
						m_sMinYbje: filterObj.m_sYbje[0].value,
						m_sMaxYbje: filterObj.m_sYbje[1].value,
						m_sFromObBm: selectObj.m_sFromObBm.value, //转出户
						m_sFromObMc: selectObj.m_izcWldx.value, //转出往来对象
						m_sSfbz: this.props.sfbz //收付标志
					};
					let dataArr = [];
					let selectedData1 = JSON.parse(JSON.stringify(selectedData));
					selectedData1.map((item, key) => {
						let valuesObj = item.data.values;
						for (let v in valuesObj) {
							valuesObj[v] = valuesObj[v].value;
						}
						if (valuesObj.this_sett != null) {
							valuesObj.isEditMoney = valuesObj.this_sett == valuesObj.sum_money_bal ? true : false;
							dataArr.push(valuesObj);
						}
					});
					let data = {
						filterConVO: filterObjData,
						selectDataVO: selectObjData,
						busidatas: dataArr
					};
					if (!!dataArr.length) {
						ajax({
							url: '/nccloud/arap/debtransfer/transfer.do',
							data,
							success: (res) => {
								let { success } = res;
								if (success) {
									this.props.cardTable.setStatus(tableid, 'browse'); //设置表格状态为浏览态
									setTimeout(() => {
										this.props.handlesetTableData(arrIndex);
									}, 0);
									toast({
										color: 'success',
										content: this.state.json['public-000204'] /* 国际化处理： 转移成功!*/
									});
								}
							}
						});
					} else {
						toast({
							color: 'warning',
							content: this.state.json['public-000216'] /* 国际化处理： 转移金额不能为空!*/
						});
						return;
					}
				} else {
					if (!m_dBbhl.value) {
						toast({
							color: 'warning',
							content: this.state.json['public-000205'] /* 国际化处理： 请选择对本币汇率!*/
						});
						return;
					} else if (!m_sClrq.value) {
						toast({
							color: 'warning',
							content: this.state.json['public-000206'] /* 国际化处理： 请选择转移日期!*/
						});
						return;
					} else {
						toast({
							color: 'warning',
							content: this.state.json['public-000207'] /* 国际化处理： 请选择转入账户!*/
						});
						return;
					}
				}
			}
		} else {
			toast({
				color: 'warning',
				content: this.state.json['public-000208'] /* 国际化处理： 请选择至少一行进行转移!*/
			});
		}
    };
    

    render() {
        let { form, button } = this.props
        let { createButtonApp } = button;
        let { createForm } = form;

        return (
            <div className="form-right">
                <div className="right-form-style">
                    {createForm("form", {
                        onAfterEvent: afterEvent.bind(this),
                        onBeforeEvent:formBeforeEvent.bind(this),
                    })}
                </div>
                <div className="right-button-style">
                    {createButtonApp({
                        area: 'list_bottom',
                        buttonLimit: 4,
                        onButtonClick: buttonClick.bind(this)
                    })}
                </div>

            </div>


        );
    }
}
DebTransFormComponent = createPage({
    initTemplate: initTemplate
})(DebTransFormComponent);

export default DebTransFormComponent;
/*AyflEomXWyqCHfdTxzWda3ExHehXzPX6thlzEnTk9yg=*/